<?php
$title = "邮箱配置";
include 'header.php';
?>
  <link href="../assets/css/sweetalert2.min.css" rel="stylesheet" type="text/css">
<!--页面主要内容-->
<div class="main-content">
    <div class="page-content">
        <div class="container-fluid">
            <!-- start page title -->
            <div class="row">
                <div class="col-xl-6 offset-xl-3">
                    <div class="card">
                        <div class="card-body">
                            <form class="custom-validation" onsubmit="return false;">
                                <div class="mb-3"><label class="form-label">邮箱服务器地址：</label>
                                    <input type="text" id="url" class="form-control"  value="<?php echo $home["emailurl"]; ?>" placeholder="请输入邮箱服务器地址">
                                </div>
                                <div class="mb-3"><label class="form-label">邮箱端口：</label>
                                    <div><input type="text" id="port" class="form-control"  value="<?php echo $home["emailport"]; ?>" placeholder="请输入邮箱端口"></div>
                                </div>
                                <div class="mb-3"><label class="form-label">邮箱用户名：</label>
                                    <div><input type="text" id="user" class="form-control"  value="<?php echo $home["emailuser"]; ?>" placeholder="请输入邮箱用户名"></div>
                                </div>
                                <div class="mb-3"><label class="form-label">邮箱密码：</label>
                                    <div><input type="text" id="pass" class="form-control"  value="<?php echo $home["emailpass"]; ?>" placeholder="请输入邮箱密码"></div>
                                </div>
                                <div class="mb-3"><label class="form-label">收件人[测试发送状态填写]：</label>
                                    <div><input type="text" id="to" class="form-control"  value="" placeholder="测试时填写，非必填"></div>
                                </div>
                                <div class="text-center">
                                    <div><button type="submit" id="submit" class="btn btn-success waves-effect waves-light">更新邮箱配置
                                        </button>&nbsp;<button type="submit" id="ceshi" class="btn btn-info  waves-effect waves-light">测试发送状态
                                        </button></div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div><!-- end col -->
            </div><!-- end row -->
        </div><!-- container-fluid -->
    </div><!-- End Page-content -->
    <footer class="footer">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-6">
                    <script>
                        document.write(new Date().getFullYear())
                    </script>(c) Cloud.
                </div>
                <div class="col-sm-6">
                    <div class="text-sm-end d-none d-sm-block">Crafted with <i class="mdi mdi-heart text-danger"></i>By <a href="https://www.9gyun.cn">云风轻产品授权中心</a></div>
                </div>
            </div>
        </div>
    </footer>
</div><!-- end main content-->
<!--End 页面主要内容-->
<?php include("footer.php"); ?>
<script src="http://lyear.itshubao.com/iframe/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="http://lyear.itshubao.com/iframe/js/lightyear.js"></script>
<script src="http://libs.itshubao.com//tinymce/tinymce.min.js"></script>
<script src="../assets/js/sweetalert2.min.js"></script>
<script language="JavaScript">
      $("#ceshi").click(function() {
        var url = $("#url").val();
        var port = $("#port").val();
        var user = $("#user").val();
        var pass = $("#pass").val();
        var to = $("#to").val();
        $.ajax({
            type: 'POST',
            url: 'set.php?act=csemail',
            data: {
                url: url,
                port: port,
                user: user,
                pass: pass,
                to:to,
                submit: 'submit'
            },
            dataType: 'json',
            success: function(data) {
                if (data.state == 1) {
                    Swal.fire("发送成功!", "恭喜你，邮件发送成功，记得保存配置哦", "success");
                } else {
                    Swal.fire("发送失败!", "配置信息有误，请检查!", "error");
                }
            }
        });

    });
    $("#submit").click(function() {
        var url = $("#url").val();
        var port = $("#port").val();
        var user = $("#user").val();
        var pass = $("#pass").val();
        $.ajax({
            type: 'POST',
            url: 'set.php?act=setemail',
            data: {
                url: url,
                port: port,
                user: user,
                pass: pass,
                submit: 'submit'
            },
            dataType: 'json',
            success: function(data) {
                if (data.state == 1) {
                    Swal.fire({
                        title: '更新成功!',
                        text: '恭喜你，更新信息成功',
                        icon: 'success',
                        confirmButtonText: 'O了个K!',
                        confirmButtonClass: 'btn btn-success mt-2',
                    });
                } else {
                    Swal.fire({
                        title: '更新失败!',
                        text: '可能信息未做更改',
                        icon: 'error',
                        confirmButtonText: '好!',
                        confirmButtonClass: 'btn btn-info mt-2',
                    });
                }
            }
        });

    });
</script>
</body>

</html>